AppleTalk Client
Volume Number: 1
Issue Number: 10
Column Tag: Pascal Procedures
"Dial a Fortune Apple Talk Client" 
By Alan Wootton, President, Top-Notch Productions, MacTutor
Contributing Editor
Fig. 1 Phone type network
AppleTalk and Macintosh Pascal
This month's topic is AppleTalk. In collaboration with Bob Denny (see the
column 'C Workshop' in this issue), I present a pair of programs that form
'Dial-A-Fortune'. The names of the two programs presented below are Get_Fortune
and Send_Fortune. These are fully conversational with Bob Denny's server version,
which performs the task of Send_Fortune. Of course, to try them, you will need two
Macs. Either my Pascal Send_Fortune or Bob's server program run in one Mac while
my Pascal Get_Fortune runs in the other Mac as the "requestor". Get_Fortune will
request fortunes from either of the C or Pascal Send_Fortune servers which respond
by sending back a fortune cookie! In this way, all the concepts of AppleTalk are
illustrated. (Note: due to space limitations, the C version of Bob's requestor program
was not included in the C column. Use my Get_Fortune requestor instead. A C requestor
program to compliment Bob's server will be published in the C workshop next month.)
If you are using Pascal, everything you need is here in this column for two way
AppleTalk communications.
I started this project with only a passing knowledge of networks. Networks are
for hooking computers together, right? So, I went to the store and bought one --
actually, two -- one for each computer. After paying $50 retail for each, I hurried
home to try it out. Shock! What you get are merely cables to wire your machines
together, and a short pamphlet on how this is done. A child could do it but having the
wires in place does not a network make. You need software.
I referred immediately to Inside Macintosh. After careful study I identified two
types of software that are needed. There are some drivers that you install in your
system like a desk accessory, or like a new printer driver, and there are Macintosh
Programs that use the drivers. Searching through the billions of disks sent to the
Apple Certified Developers uncovered the drivers (presumably you can get them at the
store too), and I installed them. Still, no network. Actually, it was like having
telephones but not knowing how to talk.
I could have gone to the store to look for software to use my network, but I decided
to write my own (actually, Bob Denny gave me Dial-A-Fortune first). So, back to the
Bible -- excuse me -- Inside Macintosh.
What I found are many programs sending many messages at many levels of
organization. The drivers send and receive data over the net at the drop of a hat. On the
top of them all seemed to be a thing called AppleTalk Transaction Protocol, ATP for
short. What this is, are some routines you can call to send and receive data (up to 512
bytes at a time). ATP is pretty clever. It will wait until it is its turn to talk, it will
retransmit requests if no reply is received, and more. In the descriptions of the
routines, I found numbers to set to indicate what data to send, and how persistent I
wanted ATP to be about delivery. I found something else, too.
To use a network to 'hook computers together' you have to know something about
the rules and conventions. Just as you cannot mail a letter without understanding
about countries, cities, streets, addresses, and names, you also cannot make a phone
call without knowing when you need an area code, or when you need a prefix, or when
you can just dial 8 and then an extension. As I found, you must tell ATP three things to
have a message delivered (refer now to the diagrams of networks in action).
Fig. 2. AppleTalk type network
First is the network number or zone (an integer). This is for situations where
your network is connected to other networks. For me this is like an area code in a
world with two telephones -- Not real useful. After ATP knows which network you're
calling, it wants to know which node you want (a byte). I had two nodes. Each
computer with a serial port, running the drivers, is a node. This is as if each of my
computers were a whole town, each meriting it's own prefix, even though there may be
only one phone in each town. Simple so far, but now my misconceptions begin to show.
This network is for connecting programs together, not computers. The final
destination of any message is a socket. For this ATP requires a socket number (a byte.
Personally, I think that 'socket' is a poor choice of words for this; it brings the image
of a connecter to mind, not a software process). This is analagous to the last four digits
of a phone number. Even though there is only one 'phone' in each of two 'towns' you
still must 'dial' an 'area code' (net number), a 'prefix' (node number), and the 'last
four' (socket number) for a 'call' to go through. So, lets send some messages!
What is the number for the place we wish to call? Telephones are considered
mostly permanent installations and are given permanent numbers (a very IBM type of
mentality). Area codes e specially won't change (even though this just happened to L.A.
when they split the city into two areas where there was previously one). For
AppleTalk the designers decided that numbers might change a lot and this would become
a drag (it would be). So they decided that they would make it so that numbers could